//
//  GPTestChatController.m
//  GuaPi
//
//  Created by 陈华 on 2017/6/20.
//  Copyright © 2017年 Joanlove. All rights reserved.
//

#import "GPTestChatController.h"
#import "GPChatController.h"
#import "GPIMController.h"


@interface GPTestChatController ()

@end

@implementation GPTestChatController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //
    
    
    
}


//登录账号A
- (IBAction)login:(id)sender {
    
    //判断是否已经设置了自动登录
    BOOL isAutoLogin = [EMClient sharedClient].options.isAutoLogin;
    if (!isAutoLogin) {
        //登录
        EMError *error = [[EMClient sharedClient] loginWithUsername:@"a" password:@"a"];
        
        //设置自动登陆
        if (!error)
        {
            [[EMClient sharedClient].options setIsAutoLogin:YES];
        }
        
    }
    
}

//登录账号B
- (IBAction)loginB:(id)sender {
    
    //判断是否已经设置了自动登录
    BOOL isAutoLogin = [EMClient sharedClient].options.isAutoLogin;
    if (!isAutoLogin) {
        //登录
        EMError *error = [[EMClient sharedClient] loginWithUsername:@"b" password:@"b"];
        
        //设置自动登陆
        if (!error)
        {
            [[EMClient sharedClient].options setIsAutoLogin:YES];
        }
        
    }
    
}



//退出当前账号
- (IBAction)logout:(id)sender {
    
    EMError *error = [[EMClient sharedClient] logout:YES];
    if (!error) {
        NSLog(@"退出成功");
    }
}

//A向B发起聊天
- (IBAction)beginChat:(id)sender {
    
    GPChatController *chatVc = [[GPChatController alloc] init];
    GPChatViewModel *chatViewModel = [[GPChatViewModel alloc]initWithChatType:EMChatTypeChat conversationId:@"b" toId:@"b" toNickName:@"b" toAvatarURLPath:@""];
    chatVc.chatViewModel = chatViewModel;
    
    [self.navigationController pushViewController:chatVc animated:YES];
    
    
}

//B向A发起聊天
- (IBAction)beginToAChat:(id)sender {
    
    GPChatController *chatVc = [[GPChatController alloc] init];
    GPChatViewModel *chatViewModel = [[GPChatViewModel alloc]initWithChatType:EMChatTypeChat conversationId:@"a" toId:@"a" toNickName:@"a" toAvatarURLPath:@""];
    chatVc.chatViewModel = chatViewModel;
    
    [self.navigationController pushViewController:chatVc animated:YES];
}

- (IBAction)im:(id)sender {
    
    GPIMController *vc = [[GPIMController alloc] init];
    vc.title = @"Intercom";
    [self.navigationController pushViewController:vc animated:YES];
}


@end
